package com.jiangjiang.eshop.wms.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.wms.convert.LogisticOrderConvert;
import com.jiangjiang.eshop.wms.dao.LogisticOrderMapper;
import com.jiangjiang.eshop.wms.domain.LogisticOrderEntity;
import com.jiangjiang.eshop.wms.dto.LogisticOrderDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author Jianghaowen
 * @Date 2021/9/17
 * @Description: TODO
 * @Version V1.0
 **/
@Service
public class LogisticOrderService extends ServiceImpl<LogisticOrderMapper, LogisticOrderEntity> {
    @Autowired
    private LogisticOrderConvert logisticOrderConvert;

    /**
     * 保存物流单数据
     * @param logisticOrderDTO 物流单数据
     * @return 处理结果
     */
    public Boolean save(LogisticOrderDTO logisticOrderDTO) {
        return this.save(logisticOrderConvert.convertDTO2Entity(logisticOrderDTO));
    }

    /**
     * 根据销售出库单id 获取物流单数据
     * @param saleDeliveryOrderId 销售出库单id
     * @return 物流单数据
     */
    public LogisticOrderDTO queryBySaleDeliveryOrderId(Long saleDeliveryOrderId) {
        LambdaQueryWrapper<LogisticOrderEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(LogisticOrderEntity::getSaleDeliveryOrderId, saleDeliveryOrderId);
        return logisticOrderConvert.convertEntity2DTO(this.getOne(wrapper));
    }

}
